package com.eportal.service.impl;

import com.eportal.dao.TLocksDeliveylogEntityMapper;
import com.eportal.domain.Sysopt;
import com.eportal.entity.TLocksDeliveylogEntity;
import com.eportal.service.BaseServiceImpl;
import com.eportal.service.TLocksDeliveylogService;
import com.framework.jqgrid.PageEntity;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Saber on 2017/8/1.
 */
@Service
public class TLocksDeliveylogServiceImpl extends BaseServiceImpl<TLocksDeliveylogEntity> implements TLocksDeliveylogService{

    @Resource
    private TLocksDeliveylogEntityMapper tLocksDeliveylogDao;

    /**
     * 智能门禁发货记录列表
     *
     * @param pageEntity       分页对象
     * @param operationContent 操作内容
     * @param operator         操作人
     * @param sendTime         操作时间
     * @param user             当前用户
     * @param userRole         当前用户userRole
     * @return
     * @author Saber
     * @Date 2017/8/1 下午1:27
     */
    @Override
    public PageInfo<TLocksDeliveylogEntity> haveSendList(PageEntity pageEntity, String operationContent, String operator, String sendTime, Sysopt user, int userRole) {
        //执行分页
        PageHelper.startPage(pageEntity.getPageNo(), pageEntity.getPageSize());
        //排序
        String orderField = pageEntity.getSort();//驼峰命名-->下划线（对应数据库字段）
        String orderDirection = pageEntity.getOrder();
        if (org.apache.commons.lang3.StringUtils.isNotEmpty(orderField)) {
            PageHelper.orderBy(orderField);
            if (org.apache.commons.lang3.StringUtils.isNotEmpty(orderDirection)) {
                PageHelper.orderBy(orderField + " " + orderDirection);
            }
        }

        String agtCode = null;
        Long sysoptId = null;

        //以前的条件
        if (userRole == 1 || userRole == 2) {
//            where.append(" and t.type =0");
        }else if (userRole == 21) {
//            where.append(" and a.sysoptId =");
//            where.append(user.getSid());
            sysoptId = user.getSid();
        }else if (userRole == 3 || userRole == 4) {
//            where.append(" and t.type =1");
//            where.append(" and t.agtCode ='");
//            where.append(user.getAgtCode());
//            where.append("' ");
            agtCode = user.getAgtCode();
        }else if (userRole == 5 || userRole == 6) {
            return null;
        }else if(userRole == 7 ){ //todo Updated by Saber on 2017/7/26 上午10:33
//			where.append(" and t.type =0");
//            where.append(" and t.agtCode ='");
//            where.append(user.getAgtCode());
//            where.append("' ");
            agtCode = user.getAgtCode();
        }

        List<TLocksDeliveylogEntity> list = tLocksDeliveylogDao.haveSendList(operationContent, operator, sendTime, userRole, sysoptId, agtCode);
        return new PageInfo<>(list);
    }

}
